/* 
 * file name : debug_log.h
 *
 * some macro of print log 
 * 
 */

#ifdef LOG_H_

#undef OPENLOG
#undef LOG
#undef PRINT_DATA
#undef LOG_H_

#endif /* #ifdef _DEBUG_LOG_H */

#define LOG_H_

#include <errno.h>
#include <syslog.h>
#include <stdio.h>
#include <time.h>

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*arr))

#define OPENLOG()

#define LOG(level, fmt, args...) \
		do { \
			int serrno = errno; \
			time_t t = time(NULL); \
			struct tm tm; \
			t = time(NULL); \
			localtime_r(&t, &tm); \
			char date[24]; \
			strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", &tm); \
			fprintf(stderr, "[%s][%s:%d] "fmt"\n", date, __FILE__, __LINE__, ## args); \
			errno = serrno; \
		} while (0)

#define PRINT_DATA(msg, datap, datalen) \
		print_data((msg), (datap), (datalen))

void print_data(const char *msg, const void *data, size_t datalen);
